{extend name="public:base"}
{block name="body"}
<body class="pear-container">
	<div class="layui-card">
		<div class="layui-card-body">
			<form class="layui-form" action="">
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">用户</label>
                    <div class="layui-input-inline">
                        <input type="text" name="keywords" placeholder="用户手机号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">设备名称</label>
                    <div class="layui-input-inline">
                        <input type="text" name="device_name" placeholder="设备名称" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <label class="layui-form-label">交易日期</label>
                    <div class="layui-inline" id="login_date">
                        <div class="layui-input-inline">
                            <input type="text" autocomplete="off" name="start_date" id="start_date"
                                class="layui-input" readonly placeholder="开始日期">
                        </div>
                        <div class="layui-form-mid">-</div>
                        <div class="layui-input-inline">
                            <input type="text" autocomplete="off" name="end_date" id="end_date" class="layui-input"
                                readonly placeholder="结束日期">
                        </div>
                    </div>
                </div>
                <div class="layui-form-item layui-inline">
                    <button class="pear-btn pear-btn-md pear-btn-primary" lay-submit lay-filter="table-query">
                        <i class="layui-icon layui-icon-search"></i>
                        查询
                    </button>
                    <button type="reset" class="pear-btn pear-btn-md">
                        <i class="layui-icon layui-icon-refresh"></i>
                        重置
                    </button>
                </div>
			</form>
		</div>
	</div>
	<div class="layui-card">
		<div class="layui-card-body">
			<table id="table-list" lay-filter="table-list"></table>
		</div>
	</div>
</body>
{/block}
{block name="custome"}
	<!--script type="text/html" id="table-toolbar">
		<button class="pear-btn pear-btn-primary pear-btn-md" lay-event="export">
			<i class="icon pear-icon pear-icon-export"></i>
			导出
		</button>
	</script-->
	<script type="text/html" id="table-bar">
        <button class="pear-btn pear-btn-primary pear-btn-sm" lay-event="edit" title="查看"><i class="icon pear-icon pear-icon-browse"></i></button>
	</script>
	{/block}
{block name="script"}
<script type="text/html" id="user-create_time">
        {{layui.util.toDateString(d.create_time, 'yyyy-MM-dd HH:mm')}}
</script>
<script type="text/html" id="user-operator">
    {{# if(d.operator == 'self')  }}
        用户
    {{# } }}
    {{# if(d.operator == 'system')  }}
        系统
    {{# } }}
    {{# if(d.operator == 'admin')  }}
        管理员
    {{# } }}
</script>
<script>
    layui.use(['table', 'form', 'jquery', 'common', 'laydate'], function () {
        let laydate = layui.laydate;
        let table = layui.table;
        let form = layui.form;
        let $ = layui.jquery;
        let common = layui.common;
        let cols = [
            [
            {
                title: 'ID',
                field: 'id',
                align: 'center',
            },
            {
                title: '账户手机号',
                field: 'user',
                align: 'center',
            },
            {
                title: '账户卡号',
                field: 'card',
                align: 'center',
            },
            {
                title: '设备名称',
                field: 'device',
                align: 'center',
            },
            {
                title: '订单号',
                field: 'order',
                align: 'center',
            },
            {
                title: '实际消费',
                field: 'expense_amount',
                align: 'center',
            },
            {
                title: '赠送消费',
                field: 'extra_amount',
                align: 'center',
            },
            {
                title: '交易日期',
                field: 'create_time',
                align: 'center',
                templet: '#user-create_time'
            },
            {
                title: '操作者',
                field: 'operator',
                align: 'center',
                templet: '#user-operator'
            }
            ]
        ]

        table.render({
            elem: '#table-list',
            url: '{:url("index")}',
            parseData: function(res){ 
            return {
            "code": res.code, //解析接口状态
            "msg": res.message, //解析提示文本
            "count": res.data.total, //解析数据长度
            "data": res.data.data //解析数据列表
            }},
            page: true,
            cols: cols,
            skin: 'line',
            toolbar: '#table-toolbar',
            defaultToolbar: [{
                title: '刷新',
                layEvent: 'refresh',
                icon: 'layui-icon-refresh',
            }, 'filter']
        });
        form.on('submit(table-query)', function (data) {
            table.reload('table-list', {
                where: data.field
            })
            return false;
        });
        table.on('tool(table-list)', function (obj) {
            if (obj.event === 'remove') {
                common.remove(obj,"{:url('batch')}");
            }
            if (obj.event === 'edit') {
                common.modalo('{:url("edit")}?ids=' + obj.data['id'],'编辑');
            }
        });

        table.on('toolbar(table-list)', function (obj) {
            if (obj.event === 'add') {
               common.modalo('{:url("add")}','新增');
            } else if (obj.event === 'refresh') {
                common.refresh();
            } else if (obj.event === 'batchRemove') {
                common.batchRemove(obj,"{:url('batch')}");
            }
        });

        laydate.render({
            elem: '#login_date'
            , range: ['#start_date', '#end_date']
        });
    })
</script>
{/block}